<!--
 * @Date: 2024-11-26 16:37:50
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-12-19 09:30:52
 * @Description: 
-->
<template>
  <EditorNode
    :row="isEmpty(row) ? schema : row"
    :config="config"
    :schema="schema"
    :upProps="upProps"
    :modelValue="handleGetValue(schema, config.field, config)"
    @update:modelValue="handleSetValue($event, config.field, config, schema)"
  >
  </EditorNode>
</template>

<script setup>
import { EditorNode } from '@hp/comps/node'

import { computed, reactive, ref } from 'vue';
import { isFunction, isEmpty } from '@hp/utils/data.js'
import { getValueByPath, setValueByPath } from '@hp/utils/data.js'

const props = defineProps({
  // 值对象
  row: { type: Object, default: () => ({}) },
  // 属性配置
  config: { type: Object, default: () => ({}) },
  // 全量数据集
  schema: { type: Object, default: () => ({}) },
  // 选中节点
  checkedNode: { type: Object, default: () => ({}) }
})

// 额外的属性
const upProps = computed(() => {
  return {
    display: true,
    ...getExtraProps()
  }
})
// 更新方法的参数
const upConfigParams = computed(() => {
  return {
    row: isEmpty(props.row) ? props.schema : props.row,
    schema: props.schema || {},
    config: props.config || {},
  }
})
/**
 * 获取额外的属性
 */
const getExtraProps = () => {
  const compProps = props.config.compProps || {}
  if (compProps.hasOwnProperty('getUpConfig') && isFunction(compProps.getUpConfig)) {
    let upProps = compProps.getUpConfig(upConfigParams.value)
    if (upProps) {
      Object.keys(upProps).forEach(key => {
        compProps[key] = upProps[key]
      })
    }
  }
  return compProps
}

const handleGetValue = (editData, field, item) => {
  const value = getValueByPath(editData, field)
  return value
}
const handleSetValue = (value, field, item, editData) => {
  setValueByPath(editData, field, value)
}
</script>

<style lang="scss" scoped>

</style>